1 package org.smartcomps.twister.engine.core.dynamic;
2
3 import junit.framework.TestCase;
4 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContextFactory;
5 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstanceFactory;
6 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstance;
7 import org.smartcomps.twister.engine.priv.core.dynamic.WaitEC;
8 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContext;
9 import org.smartcomps.twister.engine.core.definition.TestWait;
10 import org.smartcomps.twister.engine.core.definition.TestProcess;
11 import org.smartcomps.twister.common.transaction.TransactionManager;
12 import org.smartcomps.twister.common.lifecycle.LifecycleManager;
13 import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
14 import net.sf.hibernate.cfg.Configuration;
15
16 import java.util.Map;
17 import java.util.HashMap;
18
19 public class TestWaitEC extends TestCase {
20
21 public WaitEC testWaitEC = null;
22
23 private TestWait testWait = new TestWait();
24 private TestProcess testProcess = new TestProcess();
25
26 protected void setUp() throws Exception {
27 SchemaExport schemaExport = new SchemaExport(new Configuration().configure());
28 schemaExport.create(true, true);
29
30 LifecycleManager.getLifecycleManager().createResources();
31 LifecycleManager.getLifecycleManager().startResources();
32 }
33
34 protected void tearDown() throws Exception {
35 LifecycleManager.getLifecycleManager().stopResources();
36 LifecycleManager.getLifecycleManager().destroyResources();
37 }
38
39 public void testCreate() throws Exception {
40 TransactionManager.beginTransaction();
41 testProcess.testCreateWithCorrelation();
42 // Wait is using the process created in TestProcess
43 testWait.testCreateOneMn();
44
45 Map corrProp = new HashMap();
46 corrProp.put(TestProcess.CORRELATION_PROP1, "2578");
47 corrProp.put(TestProcess.CORRELATION_PROP2, "12");
48 ProcessInstance pi = ProcessInstanceFactory.createProcessInstance(TestWait.wait.getProcess(),
49 TestProcess.CORRELATION_NAME, corrProp);
50 WaitEC waitEC = (WaitEC) ExecutionContextFactory.createExecutionContext(TestWait.wait, pi);
51
52 TransactionManager.commitTransaction();
53 TransactionManager.beginTransaction();
54
55 ProcessInstance createdInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp);
56 assertTrue("Instance child ec is not a WaitEC",
57 createdInstance.getChildExecutionContext() instanceof WaitEC);
58 testWaitEC = (WaitEC) createdInstance.getChildExecutionContext();
59
60 TransactionManager.commitTransaction();
61 }
62
63 public void testExecute() throws Exception {
64 TransactionManager.beginTransaction();
65 testProcess.testCreateWithCorrelation();
66 // Wait is using the process created in TestProcess
67 testWait.testCreateOneMn();
68
69 Map corrProp = new HashMap();
70 corrProp.put(TestProcess.CORRELATION_PROP1, "2578");
71 corrProp.put(TestProcess.CORRELATION_PROP2, "12");
72
73 TestWait.wait.execute(TestProcess.CORRELATION_NAME, corrProp);
74
75 TransactionManager.commitTransaction();
76 TransactionManager.beginTransaction();
77
78 ProcessInstance createdInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp);
79 assertEquals("Process is not active after execution", ProcessInstance.ACTIVE, createdInstance.getStatus());
80 assertEquals("Wait is not active after execution", ExecutionContext.ACTIVE, createdInstance.getChildExecutionContext().getStatus());
81
82 TransactionManager.commitTransaction();
83 Thread.sleep(40000);
84 TransactionManager.beginTransaction();
85
86 createdInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp);
87 assertEquals("Process is not completed after execution ended", ProcessInstance.COMPLETED, createdInstance.getStatus());
88 assertEquals("Wait is not completed after execution ended", ExecutionContext.COMPLETED, createdInstance.getChildExecutionContext().getStatus());
89
90 TransactionManager.commitTransaction();
91 }
92 }
This page was automatically generated by Maven